package com.zycfc.zsf.boot.util.net;

public class OSUtils
{
    public static final OSType osType;
    public static final boolean WINDOWS;
    public static final boolean SOLARIS;
    public static final boolean MAC;
    public static final boolean FREEBSD;
    public static final boolean LINUX;
    public static final boolean OTHER;
    
    public static boolean isWin() {
        final OSType osType = getOSType();
        return OSType.OS_TYPE_WIN.equals(osType);
    }
    
    public static boolean isLinux() {
        final OSType osType = getOSType();
        return OSType.OS_TYPE_LINUX.equals(osType);
    }
    
    public static boolean isMac() {
        final OSType osType = getOSType();
        return OSType.OS_TYPE_MAC.equals(osType);
    }
    
    public static OSType getOSType() {
        final String osName = System.getProperty("os.name");
        if (osName.startsWith("Windows")) {
            return OSType.OS_TYPE_WIN;
        }
        if (osName.contains("SunOS") || osName.contains("Solaris")) {
            return OSType.OS_TYPE_SOLARIS;
        }
        if (osName.contains("Mac")) {
            return OSType.OS_TYPE_MAC;
        }
        if (osName.contains("FreeBSD")) {
            return OSType.OS_TYPE_FREEBSD;
        }
        if (osName.startsWith("Linux")) {
            return OSType.OS_TYPE_LINUX;
        }
        return OSType.OS_TYPE_OTHER;
    }
    
    static {
        osType = getOSType();
        WINDOWS = (OSUtils.osType == OSType.OS_TYPE_WIN);
        SOLARIS = (OSUtils.osType == OSType.OS_TYPE_SOLARIS);
        MAC = (OSUtils.osType == OSType.OS_TYPE_MAC);
        FREEBSD = (OSUtils.osType == OSType.OS_TYPE_FREEBSD);
        LINUX = (OSUtils.osType == OSType.OS_TYPE_LINUX);
        OTHER = (OSUtils.osType == OSType.OS_TYPE_OTHER);
    }
    
    public enum OSType
    {
        OS_TYPE_LINUX, 
        OS_TYPE_WIN, 
        OS_TYPE_SOLARIS, 
        OS_TYPE_MAC, 
        OS_TYPE_FREEBSD, 
        OS_TYPE_OTHER;
    }
}
